package question1;

import java.net.InetAddress;
import java.util.Scanner;

/**
 * @FileName HostToIP
 * @Description
 * @Author Sword
 * @date 2024-12-24
 **/
public class HostToIP {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入主机名: ");
        String hostname = scanner.nextLine();
        try {
            InetAddress inetAddress = InetAddress.getByName(hostname);
            System.out.println("主机名: " + hostname);
            System.out.println("IP 地址: " + inetAddress.getHostAddress());
        } catch (Exception e) {
            System.err.println("无法解析主机名: " + hostname);
        }
    }
}
